(function($){
	init=function(elem){
		var id=elem.id;
		if($("#"+id+" li").length>1){
			$.data(elem,'annouce').options.iInt=setInterval(function(){
				ul=$("#"+id+" ul");
				liheight=ul.find("li:first").height();
				ul.animate({marginTop:"-20px"},1000,function(){
					ul.find("li:first").appendTo("#"+id+" ul");
					ul.find("li:first").hide();
					ul.css("margin-top","0px");
					ul.find("li:first").show();
				});
			},$.data(elem,'annouce').options.anndelay);
			$(elem).bind('mouseenter',function(){$(this).annouce('stop');});
			$(elem).bind('mouseleave',function(){$(this).annouce('start');});
		}
	};
	$.fn.annouce =function(options, param){//options=方法或json数据,若为方法，则传递param
		if (typeof options == 'string'){
			return $.fn.annouce.methods[options](this, param);
		}
		options = options || {};
		return this.each(function(){
			var state = $.data(this, 'annouce');
			if (state){
				$.extend(state.options, options);
			} else {
				$.data(this, 'annouce', {
					options: $.extend({}, $.fn.annouce.defaults, options)
				});
				init(this);
			}
		});
	};
	$.fn.annouce.methods={
			start:function(elem){
				elem=elem[0];
				var id=elem.id;
				if($("#"+id+" li").length>1){
					$(elem).annouce('options').iInt=setInterval(function(){
						ul=$("#"+id+" ul");
						liheight=ul.find("li:first").height();
						ul.animate({marginTop:"-20px"},1000,function(){
							ul.find("li:first").appendTo("#"+id+" ul");
							ul.find("li:first").hide();
							ul.css("margin-top","0px");
							ul.find("li:first").show();
						});
					},$(elem).annouce('options').anndelay);
				}
				return elem;
			},
			stop:function(elem){
				if($.data(elem[0], 'annouce').options.iInt){
					clearInterval($.data(elem[0], 'annouce').options.iInt);
					$.data(elem[0], 'annouce').options.iInt=0;
				}
				return elem;
			},
			options:function(elem){
				return $.data(elem[0], 'annouce').options;
			}
	};
	$.fn.annouce.defaults={
			anndelay:3000,
			iInt:0
	};
})(jQuery);

jQuery.extend({
    createUploadIframe: function(id, uri)
	{
            var frameId = 'jUploadFrame' + id;
            
            if(window.ActiveXObject) {
                var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
                if(typeof uri== 'boolean'){
                    io.src = 'javascript:false';
                }
                else if(typeof uri== 'string'){
                    io.src = uri;
                }
            }
            else {
                var io = document.createElement('iframe');
                io.id = frameId;
                io.name = frameId;
            }
            io.style.position = 'absolute';
            io.style.top = '-1000px';
            io.style.left = '-1000px';

            document.body.appendChild(io);

            return io;		
    },
    createUploadForm: function(id, fileElement)
	{
		//create form	
		var formId = 'jUploadForm' + id;
		var fileId = 'jUploadFile' + id;
		var form = $('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');	
		var oldElement = $(fileElement);
		var newElement = $(oldElement).clone();
		$(oldElement).attr('id', fileId);
		$(oldElement).before(newElement);
		$(oldElement).appendTo(form);
		//set attributes
		$(form).css('position', 'absolute');
		$(form).css('top', '-1200px');
		$(form).css('left', '-1200px');
		$(form).appendTo('body');		
		return form;
    },

    ajaxFileUpload: function(s) {
        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout		
        s = jQuery.extend({}, jQuery.ajaxSettings, s);
        var id = new Date().getTime()        
		var form = jQuery.createUploadForm(id, s.fileElement);
		var io = jQuery.createUploadIframe(id, s.secureuri);
		var frameId = 'jUploadFrame' + id;
		var formId = 'jUploadForm' + id;		
        // Watch for a new set of requests
        if ( s.global && ! jQuery.active++ )
		{
			jQuery.event.trigger( "ajaxStart" );
		}            
        var requestDone = false;
        // Create the request object
        var xml = {}   
        if ( s.global )
            jQuery.event.trigger("ajaxSend", [xml, s]);
        // Wait for a response to come back
        var uploadCallback = function(isTimeout)
		{			
			var io = document.getElementById(frameId);
            try 
			{				
				if(io.contentWindow)
				{
					 xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
                	 xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
					 
				}else if(io.contentDocument)
				{
					 xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
                	xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
				}						
            }catch(e)
			{
				jQuery.handleError(s, xml, null, e);
			}
            if ( xml || isTimeout == "timeout") 
			{				
                requestDone = true;
                var status;
                try {
                    status = isTimeout != "timeout" ? "success" : "error";
                    // Make sure that the request was successful or notmodified
                    if ( status != "error" )
					{
                        // process the data (runs the xml through httpData regardless of callback)
                        var data = jQuery.uploadHttpData( xml, s.dataType );    
                        // If a local callback was specified, fire it and pass it the data
                        if ( s.success )
                            s.success( data, status );
    
                        // Fire the global callback
                        if( s.global )
                            jQuery.event.trigger( "ajaxSuccess", [xml, s] );
                    } else
                        jQuery.handleError(s, xml, status);
                } catch(e) 
				{
                    status = "error";
                    console.log(e);
                }

                // The request was completed
                if( s.global )
                    jQuery.event.trigger( "ajaxComplete", [xml, s] );
                if ( s.global && ! --jQuery.active )
                    jQuery.event.trigger( "ajaxStop" );
                if ( s.complete )
                    s.complete(xml, status);

                jQuery(io).unbind();

                setTimeout(function()
									{	try 
										{
											$(io).remove();
											$(form).remove();	
											
										} catch(e) 
										{
											jQuery.handleError(s, xml, null, e);
										}									

									}, 100)

                xml = null

            }
        }
        if ( s.timeout > 0 ) 
		{
            setTimeout(function(){
                if( !requestDone ) uploadCallback( "timeout" );
            }, s.timeout);
        }
        try 
		{
			var form = $('#' + formId);
			$(form).attr('action', s.url);
			$(form).attr('method', 'POST');
			$(form).attr('target', frameId);
            if(form.encoding){
                form.encoding = 'multipart/form-data';				
            }
            else{				
                form.enctype = 'multipart/form-data';
            }			
            $(form).submit();

        } catch(e){			
            jQuery.handleError(s, xml, null, e);
        }
        if(window.attachEvent){
            document.getElementById(frameId).attachEvent('onload', uploadCallback);
        }
        else{
            document.getElementById(frameId).addEventListener('load', uploadCallback, false);
        } 		
        return {abort: function () {}};	
    },

    uploadHttpData: function( r, type ) {
        var data = !type;
        data = type == "xml" || data ? r.responseXML : r.responseText;
        if ( type == "script" )
            jQuery.globalEval( data );
        if ( type == "json" )
            eval( "data = " + data );
        if ( type == "html" )
            jQuery("<div>").html(data).evalScripts();
        return data;
    }
});
(function($){
	$.fn.selectRange = function(start, end) {  
	    return this.each(function() {  
	        if (this.setSelectionRange) {  
	            this.focus();  
	            this.setSelectionRange(start, end);  
	        } else if (this.createTextRange) {  
	            var range = this.createTextRange();  
	            range.collapse(true);  
	            range.moveEnd('character', end);  
	            range.moveStart('character', start);  
	            range.select();  
	        }  
	    });  
	};
	$.fn.getRange=function() {
		//获取光标位置函数 var CaretPos = 0; // IE Support 
		var dom=$(this)[0];
		if (document.selection) { 
			dom.focus (); 
			var Sel = document.selection.createRange (); 
			Sel.moveStart ('character', -dom.value.length); 
			var CaretPos = Sel.text.length; 
		}else if (dom.selectionStart || dom.selectionStart == '0'){
			var CaretPos = dom.selectionStart; 
			var End=dom.selectionEnd;
		}
			
		return Array(CaretPos,End); 
	};
})(jQuery);
var dat2json=function(a){
	var b=new Array();//type=short,act=create
	var c=new Object();
	var tmp;
	b=a.split(',');//["type=short", "act=create"]
	for(var key in b){
		tmp=b[key];
		tmp=tmp.split('=');
		c[tmp[0]]=tmp[1];
	}
	return c;
};
var json2dat=function(a){
	var str="";
	var first=1;
	for(var x in a){
		if(first){
			str=x+'='+a[x];
			first=0;
		}else{
			str+=','+x+'='+a[x];
		}
	}
	return str;
};
var notify=function(message,type){//通知函数notify('消息',类型);
	var pageX=window.screen.availWidth;
	var pageY=window.screen.availHeight;
	var id=Math.round(10);
	var elem=$("<div id='alert_"+id+"'  data-dismiss='alert' class='alert alert-"+type+" fade in'>"+message+"</div>");
	elem.css({
		width:'400px',
		position:"fixed",
	 	left:(pageX-400)/2,
	  	'top':200,
	  	'z-index':'9999'
	});
	var getid=getValue(id);
	$('body').append(elem);
	setTimeout(getid,2000);//两秒暂停
};
function getValue(val){
	return function(){
		$("#alert_"+val).alert('close');
	};
}
$(document).ready(function(){
	$("textarea")[0].focus();
});
$(document).on('click',".square-type li",function(){
	$(".square-type li").removeClass('active');
	$(this).addClass('active');
	var type=$(this).attr('square-type');
	$(".square-loading").css('display','block');
	$.ajax({
		type:'post',
		url:'index.php?mod=square&action=getsquare&stype='+type,
		dataType:'html',
		success:function(data){
			$(".square-content").html(data);
			$(".square-loading").css('display','none');
		},
		error:function(){
			console.log('出现错误');
		}
	});
});
$(document).on('click',".request_reply",function(){
	var data=$.parseJSON($(this).attr('data'));
	var tid=data.tid;
	if($("#tid_"+tid+" .square-reply").length){
		console.log('reply is exist');
		$("#tid_"+tid+" .square-reply").remove();
	}else{
		$.ajax({
			type:'post',
			url:'index.php?mod=square&action=getreply&tid='+tid,
			dataType:'html',
			success:function(data){
				console.log(data);
				if($("#tid_"+tid+" .square-reply").length){
					$("#tid_"+tid+" .square-reply").remove();
				}
				$("#tid_"+tid+" .square-detail").append(data);
			},
			error:function(){
				console.log('出现错误');
			}
		});
	}
});
$(document).on('click',".send_nice",function(){
	var data=$.parseJSON($(this).attr('data'));
	console.log(data);
	var type=data.type;
	var id=data.id;
	var _this=this;
	$.ajax({
		type:'post',
		url:'index.php?mod=square&action=nice&type='+type+'&id='+id, 
		dataType:'json',
		success:function(data){
			if(data.status){
				var text=$(_this).text();
				var num=parseInt(text.match(/\d+/))+1;
				console.log(num);
				$(_this).off('click');
				$(_this).removeClass('send_nice').addClass('send_nice_ok').text('已赞('+num+')');
				console.log(_this);
			}else{
				notify('系统错误,eid:'+data.status);
			}
			
		},
		error:function(){
			console.log('出现错误');
		}
	});
});
$(document).on('keyup focus blur','.square-create textarea',function(e){
	if($(".square-create textarea").val()==''){
		$("#btn-create").attr('disabled','disabled');
	}else{
		$("#btn-create").removeAttr('disabled');
	}
});
$(document).on('keyup','.square-reply textarea',function(e){
	console.log(e.which);
	if($(".square-reply textarea").val()==''){
		$(".btn-reply").attr('disabled','disabled');
	}else{
		$(".btn-reply").removeAttr('disabled');
	}
});
$(document).on('click','#btn-create',function(){//发布
	var data=dat2json($(this).attr('data'));
	var send=new Object();
	if($(".square-create textarea").val()==''){
		return;
	}
	if(data.type=='short'){
		$(this).attr('disabled','disabled');
		send['message']=$(".square-create textarea").val();
		console.log(send);
		$.ajax({
			type:'post',
			url:'index.php?mod=square&action=create&type=short',
			data:send,
			dataType:'json',
			success:function(data){
				console.log(data);
				//object {status: 1, sid: 3} 
				switch(data.status){
				case 1:{
					$(".square-create textarea").val("");
					notify('短文章发布成功','success');
					console.log('短文章发布成功');
					$(".square-content").prepend(createSubReply(data.data));
					break;
					}
				case -1:{break;}
				case -2:{break;}
				case -3:{break;}
					default:
				}
				$("#btn-create").removeAttr('disabled');
			},
			error:function(){
				$("#btn-create").removeAttr('disabled');
				console.log('出现错误');
			}
		});
	}else if(data.type=='image'){//TODO:图片分享
		
	}else if(data.type=='video'){//TODO:视频分享
		$(this).attr('disabled','disabled');
		data['message']=$(".square-create textarea").val();
		$.ajax({
			type:'post',
			data:data,
			url:'index.php?mod=square&action=create',
			dataType:'json',
			success:function(data){
				$(".square-create textarea").val("");
			},
			error:function(){
				console.log('出现错误');
			}
		});
	}else{
		console.log('unknow type:'+data.type);
	}
	
});
$(document).on('click','.btn-share',function(){
	var share=$(this).attr('class').split(" ")[0].split('-')[1];
	if(!$(this).hasClass('selected')){
		//TODO:判断是否绑定
		var newData=$("#btn-create").attr('data')+",share="+share;
		$("#btn-create").attr('data',newData);
		$(this).addClass('selected');
	}else{
		console.log(share);
		var newData=$("#btn-create").attr('data').replace(",share="+share,"");
		$("#btn-create").attr('data',newData);
		$(this).removeClass('selected');
	}
});
$(document).on('click','.layout',function(e){
	e.stopPropagation();
});
$(document).on('click',function(){
	var isBlocked=false;
	$(".layout").each(function(){
		if($(this).css('display')=='block'){
			isBlocked=true;
		}
	});
	console.log(isBlocked);
	if(isBlocked){
		$(".layout").hide();
	}
});
$(document).on('click',".create-menu li",function(e){
	var target=$(this).attr('target');
	var parentLeft=getElementPosition($(".create-menu")[0]).absoluteLeft;
	var left=getElementPosition(this).absoluteLeft;
	var top=getElementPosition(this).absoluteTop;
	var from=$(this).parent().attr('from');
	$("."+from)
	if(target=='face'){
		getDefaultFace();
	}
	console.log("parentLeft"+parentLeft);
	console.log("left"+left);
	console.log("top"+top);
	console.log('tag'+target);
	$(".layout").each(function(){
		if($(this).css('display')=='block'){
			if($(this).hasClass(target)){
				$(".layout").hide();
				e.stopPropagation();
				return false;
			}
		}
	});
	$(".layout").hide();
	if($("."+target).css('display')=='none'){
		$("."+target).css({
			top:top+this.offsetHeight,
			left:parentLeft,
			display:"block"
		});
	}else{
		$(this).hide();
	}
	e.stopPropagation();
});
$(document).on('click','.tag-input button',function(){
	var tagname=$(".tag-input input").val();
	if(tagname){
		$(".tag-input input").val("");
		var text=$(".square-create textarea").val();
		var formatedtext=text.replace(/^#\S+#/,"");
		$(".square-create textarea").val("#"+tagname+"#"+formatedtext);
		$(".layout").hide();
		var textlength=$(".square-create textarea").val().length;
		$(".square-create textarea").selectRange(textlength,textlength);
	}
});
$(document).on('click','.nine-block li img',function(){
	var imgsrc=$(this).attr('res');
	$(this).removeClass('img-big');
	$(this).addClass('img-bigable');
	var parentid=$(this).parents('.square-sub').attr('id');
	console.log(parentid);
	$("#"+parentid+" .square-media").hide();
	var imgselectbox=$("<div class='select-box'></div>");
	var ul=$("#"+parentid+" .nine-block").clone();
	ul.removeClass('nine-block').addClass('ul-bigable');
	ul.find('.img-big').removeClass('img-big').addClass('clk-big');
	$(this).removeClass('img-bigable');
	$(this).addClass('img-big');
	imgselectbox.append(ul);
	imgselectbox.append("<div style='clear:both'></div>");
	var p=$('<p class="bigable-menu"><a href="javascript:;" action-type="tosmall" class="retract">收起</a><i class="W_vline">|</i><a action-type="images_view_tobig" class="show_big">查看大图</a></p>');
	var bigimg=$("<div class='bigimg'><img src="+imgsrc+" /></div>");
	$("#"+parentid+" .expand").append(p);
	$("#"+parentid+" .expand").append(bigimg);
	$("#"+parentid+" .expand").append(imgselectbox);
});
$(document).on('click','.clk-big',function(){
	var ul=$(this).parents('.ul-bigable');
	var imgsrc=$(this).attr('res');
	ul.find('.img-bigable').removeClass('img-bigable').addClass('clk-big');
	$(this).removeClass('clk-big').addClass('img-bigable');
	$(this).parents('.bigimg').children().attr('src',imgsrc);
});
$(document).on('click','.video-big',function(){
	var urlsrc=$(this).attr('res');
	var parentid=$(this).parents('.square-sub').attr('id');
	console.log(parentid);
	var p=$('<p class="bigable-menu"><a href="javascript:;" action-type="tosmall" class="retract">收起</a></p>');
	$.ajax({
		type:'post',
		url:'index.php?mod=misc&action=getvideo&url='+urlsrc,
		dataType:'text',
		success:function(data){
			//console.log(data);
			if(data){
				$("#"+parentid+" .square-media").hide();
				$("#"+parentid+" .expand").append(p);
				$("#"+parentid+" .expand").append(data);
			}else{
				console.log('无数据');
			}
			
		},
		error:function(){
			console.log('出现错误');
		}
	});
	
});
$(document).on('click','.retract',function(){
	var parentid=$(this).parents('.square-sub').attr('id');
	$("#"+parentid+" .square-media").show();
	$(this).parents('.expand').empty();
});
$(document).on('click','.btn-checkin',function(){
	$.ajax({
		type:'post',
		url:'index.php?mod=user&action=checkin',
		dataType:'json',
		success:function(data){
			console.log(data);
			switch(data.status){
			case 1:{
				$(".btn-checkin").text('已签到');
				$(".btn-checkin").attr('disabled','disabled');
				$(".btn-checkin").removeClass('btn-checkin');
				$(".check-today").text('第'+data.cid+'名');
				notify('签到成功','success');
				console.log('签到成功');
				break;
				}
			case -1:{break;}
			case -2:{break;}
			case -3:{break;}
				default:
			}
		},
		error:function(){
			console.log('出现错误');
		}
	});
});
$(document).on('click','.btn-share-video',function(){
	var url=$(".btn-share-video").parent().children('input').val();
	if(/^http:\/\/\w{0,3}.\w{1,}.\w{1,}/.test(url)){
		$.ajax({
			type:'post',
			url:'index.php?mod=misc&action=checkvideo&url='+url,
			dataType:'json',
			success:function(data){
				switch(data.status){
				case '1':{
					var btndata=dat2json($("#btn-create").attr('data'));
					btndata.type='video';
					btndata.imgurl=data.imgurl;
					btndata.flv=data.flv;
					btndata.url=url;
					$("#btn-create").attr('data',json2dat(btndata));
					$(".layout").hide();
					if($(".square-create textarea").val()==''){
						$(".square-create textarea").val('我分享了一个视频');
					}
					$(".square-create textarea")[0].focus();
					break;
				}
				case '-1':{
					$(".btn-share-video").parent().children('input').addClass('notsupport');
					break;
				}
				}
			},
			error:function(){
				console.log('出现错误');
			}
		});
	}else{
		$(".btn-share-video").parent().children('input').addClass('error');
	}
});
$(document).on('click','.btn-upload-video',function(){
	var attach=$(this).parent().children('input').val();
	if(attach){
		$.ajaxFileUpload({
             url:'index.php?mod=misc&action=upload',
             fileElement:$(this).parent().children('input'),
             dataType: 'json',
             success: function (data, status){
                $('#result').html('添加成功');
             }
        });
		var btndata=dat2json($("#btn-create").attr('data'));
		btndata.type='video';
		$("#btn-create").attr('data',json2dat(btndata));
		$(".layout").hide();
		if($(".square-create textarea").val()==''){
			$(".square-create textarea").val('我分享了一个视频');
		}
		$(".square-create textarea")[0].focus();
	}
});
$(document).on('click','.square-getnew',function(){
	$(this).hide();
	$(".square-loading").css('display','block');
	var tid=$('.square-sub:last').attr('id').split('_')[1];
	console.log(tid);
	$.ajax({
		type:'post',
		url:'index.php?mod=square&action=refreshData&tid='+tid,
		dataType:'json',
		success:function(data){
			console.log(data);
			switch(data.status){
			case 0:{
				$(".square-loading").hide();
				$(".square-nonew").show();
				$(".square-getnew").hide();
				break;
			}
			case 1:{
				for(var x in data.data){
					$(".square-content").append(createSubReply(data.data[x]));
				}
				$(".square-loading").hide();
				$(".square-getnew").show();
				break;
				}
			case -1:{break;}
			case -2:{break;}
			case -3:{break;}
				default:
			}
		},
		error:function(){
			console.log('出现错误');
		}
	});
	
});
$(document).on('click','.btn-reply',function(){
	$(this).attr('disabled','disabled');
	var tid=$(this).parents('.square-sub').attr('id').split('_')[1];
	var send=$(this).parents('.square-reply form').serializeArray();
	var _this=this;
	$.ajax({
		type:'post',
		url:'index.php?mod=square&action=reply&tid='+tid,
		data:send,
		dataType:'json',
		success:function(data){
			console.log(data);
			switch(data.status){
			case 0:{
				break;
			}
			case 1:{
				var replies=parseInt($(_this).parents('.square-sub').find('.replies').text());
				$(_this).parents('.square-sub').find('.replies').text(replies+1);
				$(_this).parents('.square-sub').find('.square-reply>ul').append(data.reply);
				$(".square-reply textarea").val("");
				notify('回复成功','success');
				break;
				}
			case -1:{break;}
			case -2:{break;}
			case -3:{break;}
				default:
			}
		},
		error:function(){
			console.log('出现错误');
		}
	});
	
});
$(document).on('click','.reply_reply',function(){
	
	//TODO:回复回复
	var elem=$("<div class='reply-subreply'></div>");
	$(".reply-subreply").append("<div class='subreply-main'></div>");
	$(".subreply-main").append('<textarea action-type="check" class="W_input" node-type="textEl" name="" rows="" cols="" range="0&amp;0" style="margin: 0px 0px 5px; padding: 5px 0px 0px 2px; border-style: solid; border-width: 1px; overflow: hidden; height: 23px; font-size: 12px; font-family: Tahoma, 宋体; word-wrap: break-word; line-height: 18px; outline: none;"></textarea>');
	$(this).parents('.reply-detail').append(elem);
});
$(document).on('scroll',function(e){
	var scrolly=window.scrollY;
	var elemy=$(".square-loss").offset().top+$(".square-loss")[0].clientHeight;
	var width=$(".square-hot")[0].clientWidth;
	if(scrolly>elemy){
		$(".square-hot").addClass('square-hot-scrolled');
		$(".square-hot-scrolled").css('width',width);
	}else{
		$(".square-hot").removeClass('square-hot-scrolled');
	}
});
$(document).on('click','.tag-list>ul>li>a',function(){
	console.log($(this).text());
	var tagname=$(this).text();
	var text=$(".square-create textarea").val();
	var formatedtext=text.replace(/^#\S+#/,"");
	$(".square-create textarea").val("#"+tagname+"#"+formatedtext);
	$(".layout").hide();
	var textlength=$(".square-create textarea").val().length;
	$(".square-create textarea").selectRange(textlength,textlength);
});
$(document).on('click','.detail-list img',function(){
	var facecode=$(this).attr('alt');
	var target=$("textarea[selected='selected']")
	var textval=target.val();
	var range=target.attr('range').split('&');
	var textval=textval.substring(0,range[0])+facecode+textval.substring(range[1],textval.length);
	target.val(textval);
	target.selectRange(parseInt(range[0])+facecode.length,parseInt(range[0])+facecode.length);
	$(".layout").hide();
});
$(document).on('click mouseup keyup','textarea',function(){
	var range=$(this).getRange();
	range=range.join('&');
	$(this).attr('range',range);
	$("textarea").removeAttr('selected');
	$(this).attr('selected','true');
});
$(document).on('click','.show_big',function(){
	var expand=$(this).parents('.expand');
	var currenturl=expand.find('.bigimg img').attr('src');
	window.open(currenturl);
});
function getElementPosition(element) 
{ 
    if ( arguments.length != 1 || element == null ) 
     { 
        return null; 
     } 
    var elmt = element; 
    var offsetTop = elmt.offsetTop; 
    var offsetLeft = elmt.offsetLeft; 
    while( elmt = elmt.offsetParent ) 
     {          
        if ( elmt.style.position == 'absolute' || elmt.style.position == 'relative' 
            || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) ) 
         { 
            break; 
         } 
         offsetTop += elmt.offsetTop; 
         offsetLeft += elmt.offsetLeft; 
     } 
    return { absoluteTop: offsetTop, absoluteLeft: offsetLeft}; 
}

function createSubReply(subReply){
	var elem=$("<div id=\"tid_"+subReply.tid+"\" class=\"square-sub\"></div>");
	elem.append("<div class=\"square-headimg\"></div>");
	elem.children().append("<img onerror=\"this.onerror=null;this.src='../ucenter/images/noavatar_small.gif'\" />");
	elem.find('img').attr('src','../ucenter/avatar.php?uid='+subReply.authorid+'&size=small');
	elem.append("<div class=\"square-detail\"></div>");
	elem.find('.square-detail').append("<div class=\"square-username\"></div>");
	elem.find('.square-username').append("<a href=\"index.php?mod=user&amp;action=view&amp;uid="+subReply.authorid+"\">"+subReply.author+"</a>");
	elem.find('.square-detail').append("<div class=\"square-text\"></div>");
	elem.find('.square-text').html(subReply.message);
	elem.find('.square-detail').append("<div class=\"square-bottom\"></div>");
	elem.find('.square-bottom').append('<div class=\"square-time\">刚刚发布</div>');
	elem.find('.square-bottom').append('<div class="square-stat"><ul class="nav nav-pills nav-sm nav-nobg"><li><a class="send_nice" href="javascript:void(0);" data="{&quot;type&quot;:&quot;tid&quot;,&quot;id&quot;:'+subReply.tid+'}">赞('+subReply.nice+')</a></li><li><a class="request_reply" href="javascript:void(0);" data="{&quot;tid&quot;:'+subReply.tid+'}">评论(<span class="replies">'+subReply.replies+'</span>)</a></li><li><a>分享('+subReply.shared+')</a></li></ul></div>');
	elem.find('.square-bottom').append('<div style="clear:both"></div>');
	return elem;
}
function getDefaultFace(){
	var data=$(".face-type li[class='selected']").attr('data');
	data=$.parseJSON(data);
	if(!$("#face_"+data.typeid).length){
		$.ajax({
			type:'post',
			url:'index.php?mod=misc&action=smiley&smileid='+data.typeid,
			dataType:'json',
			success:function(resdata){
				var face=$(".face-detail:last").clone();
				face.attr('id','face_'+data.typeid);
				for(x in resdata){
					console.log(resdata[x]);
					face.find('ul').append('<li><img src="static/img/smiley/'+data.directory+'/'+resdata[x].smileurl+'" width="25" height="25" alt="'+resdata[x].smilename.replace(/\/|\\/g,'')+'"></li>');
				}
				face.find('.face-page').hide();
				$(".face-detail").hide();
				$(".face").append(face);
			},
			error:function(){
				console.log('出现错误');
			}
		});
	}else{
		$(".face-detail").hide();
		$("#face_"+data.typeid).show();
	}
}